<template>
  <el-dialog
      title="更改教师"
      :visible.sync="visible"
      :id.sync="id"
      :before-close="closeDialog"
      @opened="openDialog"
      width="400px">
    <el-form label-width="80px">
      <el-form-item label="教室" prop="classroom.classroomId" size="small">
        <el-select v-model="classroom.classroomId">
          <el-option
              v-for="item in classrooms"
              :key="item.classroomId"
              :label="item.classroomCode"
              :value="item.classroomId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item align="center" style="margin-left: -80px;">
        <el-button type="primary" size="small" plain @click="handleUpdate">修改设备</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import {getActivityRoomApplicationById, updateActivityRoomApplication} from "@/api/activityRoomApplication";
import {listActivityRoomApplications} from "@/api/activityRoomApplication";

export default {
  name: 'ActivityRoomApplicationBindDialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    id: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      classroom: {},
      classrooms: [],
    }
  },
  methods: {
    // 更新设备信息
    handleUpdate() {
      updateActivityRoomApplication({
        'activeTime': this.activityRoomApplication.activeTime,
        'activityDate': this.activityRoomApplication.activityDate,
        'activityDescription': this.activityRoomApplication.activityDescription,
        'activityNumber': this.activityRoomApplication.activityNumber,
        'activityTime':this.activityRoomApplication.activityTime,
        'applicant': this.activityRoomApplication.applicant,
        'classroomId': this.activityRoomApplication.classroomId,
        'classroomNumber':this.activityRoomApplication.classroomNumber,
        'applicationTime':this.activityRoomApplication.applicationTime,
      }).then((response) => {
        if (response.data.code === 200) {
          this.$parent.fetchData()
          this.$alert('提交成功', '提示', {
            confirmButtonText: '确定'
          })

        } else {
          this.$alert('提交失败', '提示', {
            confirmButtonText: '确定'
          })
        }
      })
      this.$emit('update:visible', false)
    },

    // 打开对话框
    openDialog() {
      listActivityRoomApplications(1, 20).then((response) => {
        this.seats = response.data.data.list;
      })
      getActivityRoomApplicationById(this.activityRoomApplication).then((response) => {
        this.activityRoomApplication = response.data.data;
      })
      console.log(this.seats);
    },

    // 关闭对话框
    closeDialog() {
      this.$emit('update:visible', false)
    },
  }
}
</script>

<style scoped>

</style>
